﻿ Validator = {   
     Require : /.+/,   
     Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,   
     Phone : /^((\(\d{3}\))|(\d{3}\-?))?(\(0\d{2,3}\)|0\d{2,3}-?)?[1-9]\d{6,7}(\-\d{1,4})?$/,   
     Mobile : /^((\(\d{3}\))|(\d{3}\-))?1\d{10}$/,   
     Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,  
     IdCard : /^\d{15}(\d{2}[A-Za-z0-9])?$/,  
     Currency : /^\d+(\.\d+)?$/,  
     Number : /^\d+$/,  
     Zip : /^[1-9]\d{5}$/,  
     QQ : /^[1-9]\d{4,8}$/,  
     Integer : /^[-\+]?\d+$/,  
     Double : /^[-\+]?\d+(\.\d+)?$/,  
     English : /^[A-Za-z]+$/,  
     Chinese : /^[\u0391-\uFFE5]+$/,  
     Password : /^[a-zA-Z0-9_\\-]{6,}$/i,
     Username : /^[\u0391-\uFFE5a-zA-Z0-9_\\-]{2,}$/i
 };
 $.xcall={
    rootpath:"/Script/"
 }
$.fn.xcall=function(){
    var fns=$(this).attr("xcall");
    if(fns){
        fns=fns.split(",");
        var _thisx=this;
        for(var n=0;n<fns.length;n++){
            var fn=fns[n];
            var fnattr=$(_thisx).attr(fn)||$(_thisx).attr("xcall_"+fn);

            if(fnattr){
                if(fnattr.indexOf("{")==0&&fnattr.lastIndexOf("}")==fnattr.length-1){
                    var xx="var args=["+fnattr+"];"
                    eval(xx);
                }else{
                    var args=fnattr.split(",");
                }				   
                try{       
                    $(_thisx)[fn].apply(_thisx,args);
                }catch(e){
                    alert("因为网速过慢或者其他网络环境因素，本页所需资源加载失败:"+fn+",请重新刷新");
                }	                      
            }else{
                $(_thisx)[fn]();
            } 
        }				            	
    }
};   
    
(function($) {
    $.fn.textarea125 = function(options) {
        var guid = new Date().getTime() + parseInt(10000 * Math.random());
        $(this).attr("textarea125id", guid);
        var span = $("<span id=\"span" + guid + "\"><br />最多可输入125个字(" + $(this).val().length + "/125)</span>");
        $(this).after(span);
        $(this).get(0).onkeyup = function() {
            var length = $(this).val().length;
            if (length > 125) {
                $(this).val($(this).val().substring(0, 125));
                return false;
            }
            $("#span" + guid).html("<br />最多可输入125个字(" + $(this).val().length + "/125)");
        };
    }

    $.fn.IntTextBox = function(options) {
        var obj = $(this);
        var val =$.trim(obj.val());
        obj.keyup(function() {
            CheckVal();
        });
        obj.blur(function() {
            CheckVal();
        });
        function CheckVal() {
            if (obj.val()!=""&&!Validator.Integer.test(obj.val())) {
                obj.val(val);
            }
            else {
                val = obj.val();
            }
        }
    }
    $.fn.onlynumber = function(options) {
        $(this).keydown(function(evt) {
            if ((evt.keyCode >= 96 && evt.keyCode <= 105) || (evt.keyCode >= 48 && evt.keyCode <= 57) || evt.keyCode == 127 || evt.keyCode == 8) {
                return true;
            }
            if ((evt.keyCode < 48 || evt.keyCode > 57) && evt.keyCode != 127 && evt.keyCode != 8) {

                return false;
            }
        });
    }
})(jQuery);


(function($) {
    $.fn.xlink = function(options) {
        var documenturl = location.href;
        var index = documenturl.lastIndexOf("/");
        var baseurl = documenturl.substring(0, index + 1);
        var id = null;
        options = $.extend({
            target: "top",
            cover: true,
            refresh: true,
            position: null,
            width: null,
            height: null
        }, options);
        var text = $(this).text();
        if ($(this).attr("title")) {
            text = $(this).attr("title");
        }
        var href = $(this).attr("href");
        if (href.indexOf("/") == 0 || href.indexOf("http") == 0) {

        } else {
            href = baseurl + href;
        }
        $(this).click(function() {
            window.location.href = href;
        });
    }
    $("a").click(function(){
        $(this).blur();
    });  
    $.ClearBody=function(){
        var msg="页面已过期";
        $("body").html(msg);
    }
})(jQuery);
    
$.Ready=function(fn){
    $(document).ready(fn);
};

function ToggleWindow(guid){
    if($("#popwind"+guid).attr("size")){
        var size=$("#popwind"+guid).attr("size");
        var width=size.split(",")[0]*1;
        var height=size.split(",")[1]*1;
        var x=size.split(",")[2]*1;
        var y=size.split(",")[3]*1;
         $("#popwind"+guid).removeAttr("size");
         $("#popwind"+guid).css({left:x+"px",top:y+"px"}).width(width).height(height);
        var iframe= $("#popwind"+guid).find("iframe");
        iframe.width($("#popwind"+guid).width()-19).height($("#popwind"+guid).height()-31); 
    }else{
        var size=$("#popwind"+guid).width()+","+$("#popwind"+guid).height()+","+$("#popwind"+guid).position().left+","+$("#popwind"+guid).position().top;
        $("#popwind"+guid).attr("size",size);
        var width=$(window).width();
        var height=$(window).height();
        $("#popwind"+guid).css({left:0,top:"10px"}).width(width-30).height(height-30);
        var iframe= $("#popwind"+guid).find("iframe");
        iframe.width($("#popwind"+guid).width()-19).height($("#popwind"+guid).height()-31);
   }
}

var popboxzindex=10;
function AddWindow(name, url, options) {
    
    var winwidth=$(top.window).width();
    var winheight=$(top.window).height()-100;
    var cols=top.window.document.getElementById("midframeset").cols;
    if(cols=="196,10,*"){
        winwidth=winwidth-200;
    }else{
        winwidth=winwidth-5;
    }
    options = $.extend({
        target: "pop",
        cover: true,
        refresh: true,
        position: null,
        width: winwidth * 8 / 10,
        height: winheight * 8 / 10,
        ResizeStopFunc: function(popwindow,w,h) { }  //缩放停止事件
    }, options); 
	  popboxzindex+=2;	 
    var guid=new Date().getTime();
    var winwidth = options.width - 20;
    var winheight = options.height - 31;
    var html='<div class="popBox" id="popwind'+guid+'" style="width:'+options.width+'px;height:'+options.height+'px;z-index:'+popboxzindex+'">'+
    '<table cellspacing="0" cellpadding="0" border="0" width="100%">'+
      '<tbody><tr>'+
        '<td height="21" width="10" class="popTL"><div></div></td>'+
        '<td height="21" class="popTB" ondblclick="ToggleWindow('+guid+')"><span onclick="CloseWindow('+guid+','+options.refresh+')"></span>&nbsp;</td>'+
        '<td height="21" width="10" class="popTR"><div></div></td>'+
      '</tr>'+
      '<tr>'+
        '<td width="10" class="popCL"><div></div></td>'+
        '<td background="#cd7c3b" >' +
           //'<iframe  width="' + winwidth + '" height="' + winheight + '"  style="width:' + winwidth + 'px;height:' + winheight + 'px;border:0; marign:0;padding:0" src="' + url + '" frameborder="0" ></iframe>' +
           '<iframe height="' + winheight + '"  style="width:100%;height:' + winheight + 'px;border:0; marign:0;padding:0" src="' + url + '" frameborder="0" ></iframe>' +
        '</td>'+
        '<td width="10" class="popCR"><div></div></td>'+
      '</tr>'+
      '<tr>'+
        '<td width="10" class="popBL"><div></div></td>'+
        '<td><div class="popBB"></div></td>'+
        '<td width="10"><div class="popBR"></div></td>'+
      '</tr>'+
    '</tbody></table>'+
'</div>';
    $(html).appendTo($(document.body));
     var coverw=$(document).width();
     var coverh=$(document).height();
     if(coverw<$(window).width()){
        coverw = $(window).width();
     }
     if(coverh<$(window).height()){
        coverh = $(window).height();
     }
    
    if(options.position){
        $("#popwind" + guid).css({ left: options.position.x + "px", top: options.position.y + "px" });
    }else{
        var w = ($(window).width() - options.width) / 2 + $(window).scrollLeft();
        var h = ($(window).height() - options.height) / 2 + $(window).scrollTop();
        if ($.browser.msie) {
            w -= 40;
        }
        $("#popwind"+guid).css({left:w+"px",top:h+"px"});
    }
   if(options.cover){
        var cover=$(".popboxcover[tag='"+guid+"']");
        if(cover.size()==0){
          cover=$("<div class='popboxcover' tag='"+guid+"' style='z-index:"+(popboxzindex-1)+"'>");
          cover.appendTo($(document.body));
        }
        cover.css({position:"absolute",left:0,top:0,background:"#000000",opacity:0.5});
        
        cover.width(coverw).height(coverh);
    }
   $("#popwind" + guid).draggable();
    /*$("#popwind" + guid).resizable({
        handles: "se",
        helper: true,
        autoHide: false,
        //aspectRatio:true,
        stop: function(ev, ui) {
            $(this).find("table").width(ui.size.width).height(ui.size.height);
            //$(this).find("table").width( $(this).width()).height( $(this).height());
            var iframe = $(this).find("iframe");
            iframe.height($(this).height() - 31); //.width(ui.size.width - 16);
            if (options.ResizeStopFunc) {
                options.ResizeStopFunc(iframe.contents(), ui.size.width, ui.size.height);
            }
        }
    }).draggable();    */
   if ($.browser.msie && $.browser.version == '8.0') {
           if (window.top.hideLeftframe != null) {
               window.top.hideLeftframe();
               window.top.hideLeftframe();
           }
   }
    return guid;
}
function CloseWindow(guid,refresh){
    $(".popboxcover[tag='"+guid+"']").remove();
    $("#popwind"+guid).remove();
    if(refresh){
        if(jQuery("input.updatebtn").size()>0){
            jQuery("input.updatebtn").click();
        }else{
            window.location.reload();
        }
    }
    if ($.browser.msie && $.browser.version == '8.0') {
        if (window.top.hideLeftframe != null) {
            window.top.hideLeftframe();
            window.top.hideLeftframe();
        }
    }
}
var prevURL = window.top.returnUrl;
window.top.returnUrl = window.location.href;   //设置需要返回的上一级页面
function CloseMe(text){
    if(text&&text!=""){
        alert(text);
    }
    if (prevURL != null && prevURL != "") {
        window.location.href = prevURL;
    }
}

function ClosePage(text) {
    if (text && text != "") {
        alert(text);
    }
    jQuery(window.frameElement.parentNode).closest("table").find(".popTB span").click();
}
function Callback(value,text){
    if(window.CallbackFn){
        window.top.window["windowdic"]["w"+window.CallbackFn]["callback"+window.CallbackFn](value,text);
    }
}

$.Ready(function() {
    $("[xcall]").each(function() {
        $(this).xcall();
    });
    if (!window.AlwaysShowRemindmsgs) {
        setTimeout(function() {
            $(".remindmsgs").slideUp(1000);
        }, 5000);
    }
});
function ShowCopyRight() {
    var dHeight = $(document).height();
    var wHeight = $(window).height();
    //$("body").append("<div class='copyright'>成都驰创数码科技有限公司版权所有，未经允许不得使用或传播！</div>");    
    setTimeout(function() {
        $("form div").last().after("<div class='copyright'>成都驰创数码科技有限公司版权所有，未经允许不得使用或传播！</div>");
        if (wHeight < dHeight) {
            $(".copyright").css("top", dHeight - $(".copyright").height());
        }
    }, 500);
    if ($.browser.msie && $.browser.version == '8.0') {
        setTimeout(function() {
            $("#warp").width($(top.document).width() - 223);
            if (window.top.hideLeftframe != null) {
                window.top.hideLeftframe();
                window.top.hideLeftframe();
            }

        }, 1000);
    }
}
$(function() {
    $(".artEditBtn").width($(".artEditBtn a").size() * 50).children().removeAttr("width");
    $(".artEditBtn a").each(function() {

        $(this).css({ backgroundImage: "url('/manage/Resources/default/images/icos/" + $(this).attr("ico").replace("icon-", "") + ".png')" });
//        if (jQuery.browser.msie && (jQuery.browser.version == "6.0") && !jQuery.support.style) {
//            $(this).css({ background: "none" });
//            $(this).css({ _filter: "progid:DXImageTransform.Microsoft.AlphaImageloader(src='/manage/Resources/default/images/icos/" +$(this).attr("ico").replace("icon-", "") + ".png',sizingMethod='scale');" });
//            $(this).css({ backgroundImage: "url('/manage/Resources/default/images/icos/" + $(this).attr("ico").replace("icon-", "") + ".png')" });
//        }
//        else {
//             $(this).css({ backgroundImage: "url('/manage/Resources/default/images/icos/" + $(this).attr("ico").replace("icon-", "") + ".png')" });
//        }
    });
    $(".artTab tbody tr").hover(
        function() {
            $(this).css({ backgroundColor: "#ffd245" })
        },
        function() {
            $(this).css({ backgroundColor: "#FBFBFB" })
        }
    );
});
